<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--bootstrap插件-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="/static/plugin/bootstrap/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/static/plugin/jo/joUI.css" rel="stylesheet"/>
    <!--字体插件-->
    <link href="/static/plugin/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/plugin/layui-2.4.3/css/layui.css" rel="stylesheet"/>
    <!--ztree-->
    <link href="/static/plugin/zTree/css/metroStyle/metroStyle.css" rel="stylesheet"/>
    <!--common-->
    <link href="/static/css/common.css" rel="stylesheet"/>
    <title>登录认证会话信息视图</title>
</head>
<body class="skin-default">

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12">

            <div class="container-fluid card">
                <div class="row">
                    <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
                        <!--检索栏-->
                        <form class="form-inline search-bar" id="pageForm">
                            <div class="form-group">
                                <label class="control-label">用户ID：&nbsp;</label>
                                <input type="text" name="userId" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label">令牌：&nbsp;</label>
                                <input type="text" name="token" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label">设备类型：&nbsp;</label>
                                <select name="deviceType" class="form-control">
                                    <option value=""></option>
                                    <option value="H5">H5</option>
                                    <option value="ANDROID">ANDROID</option>
                                    <option value="IOS">IOS</option>
                                    <option value="WINDOWSPHONE">WINDOWSPHONE</option>
                                </select>
                            </div>
                           <!-- <div class="form-group">
                                <label class="control-label">设备版本号：&nbsp;</label>
                                <input type="text"   name="deviceVersion" class="form-control"/>
                            </div>-->
                            <div class="form-group">
                                <label class="control-label">客户端IP：&nbsp;</label>
                                <input type="text" name="clientIp" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label">服务器IP：&nbsp;</label>
                                <input type="text" name="serverIp" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label">令牌签发时间：&nbsp;</label>
                                <div class="input-group">
                                    <input type="text" name="signTime" id="signTime" class="form-control">
                                    <span class="input-group-addon" style="border-width: 1px 0px;">~</span>
                                    <input type="text" name="signTime2" id="signTime2" class="form-control">
                                </div>
                            </div>
                            <button type="button" class="btn btn-primary" onclick="joView.select()"> <i class="fa fa-search" aria-hidden="true"></i>&nbsp;查询</button>
                        </form>
                        <!--/检索栏-->
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
                        <!--按钮栏-->
                        <div class="form-group button-bar">
                            <!--<button isShow="" type="button" class="btn btn-primary" onclick="joView.add()">
                                <i class="fa fa-plus" aria-hidden="true"></i>&nbsp;新增
                            </button>-->
                            <!--<button type="button" class="btn btn-info" onclick="offLine()">
                                <i class="fa fa-unlink" aria-hidden="true"></i>&nbsp;下线
                            </button>-->
                            <button type="button" class="btn btn-danger" onclick="joView.del()">
                                <i class="fa fa-trash-o" aria-hidden="true"></i>&nbsp;删除
                            </button>
                            <button type="button" class="btn btn-warning" onclick="window.location.reload()">
                                <i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;刷新
                            </button>
                        </div>
                        <!--/按钮栏-->
                    </div>
                </div>
                <div class="row">
                <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
                    <div class="table-bar">
                        <!--grid-->
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover" id="mainList" dataUrl="{URL_UMS}ums/ssoSession/getPage" deleteUrl="{URL_UMS}ums/ssoSession/delete" formUrl="/page/ums/ssoSessionForm.html">
                                <col field="userId" title="用户ID" width="20%" align="" event="click" />
                                <col field="{deviceType}-{deviceVersion}" title="设备类型" width="15%" align=""  />
                                <!--<col field="deviceVersion" title="设备版本号" width="15%" align=""  />-->
                                <col field="token" title="令牌" width="20%" align=""  />
                                <col field="[=jo.formatTime('{signTime}')]" title="令牌签发时间" width="15%" align=""  order="signTime"/>
                                <col field="expireTime" title="令牌过期时间" width="15%" align=""  order="expireTime"/>
                                <col field="clientIp" title="客户端IP" width="12%" align=""  />
                                <!--<col field="serverIp" title="服务器IP" width="10%" align=""  />-->
                                <col field="statusMark" title="状态" width="10%" align=""  />
                                <col field="opt" title="操作" width="150px" align=""  />
                            </table>
                        </div>
                        <!--/grid-->

                        <!--分页条-->
                        <div class="page-bar" gridId="mainList">

                        </div>
                        <!--/分页条-->
                    </div>
                </div>
            </div>
            </div>

        </div>
    </div>
</div>

<!--配置信息-->
<script src="/static/js/config.js"></script>
<!--jquery-->
<script src="/static/plugin/jquery/jquery-3.3.1.js"></script>
<script src="/static/plugin/jquery/jquery.cookie.js"></script>
<!--bootstrap-->
<script src="/static/plugin/bootstrap/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="/static/plugin/other/html5shiv.js"></script>
<script src="/static/plugin/other/respond.min.js"></script>
<![endif]-->
<!--layui-->
<script src="/static/plugin/layui-2.4.3/layui.all.js"></script>
<!--ztree-->
<script src="/static/plugin/zTree/js/jquery.ztree.all.js"></script>
<!--common-->
<script src="/static/js/common.js"></script>
<!--jo-->
<script src="/static/plugin/jo/jo.js"></script>
<script src="/static/plugin/jo/jo-adapt.js"></script>
<script src="/static/plugin/jo/jo-page-view.js"></script>
<script src="/static/plugin/jo/jo-page-form.js"></script>
<script src="/static/plugin/jo/jo-listener.js"></script>
<script type="text/javascript">
    layui.laydate.render({
        elem: '#signTime' //注册日期控件
    });
    layui.laydate.render({
        elem: '#signTime2' //注册日期控件
    });
    $(function(){
        joView.init({grid:$("#mainList"),PKName:"id"});//初始化页面
    });
    //表格渲染时行处理,参数1为当前行的数据对象,参数2为当前行的索引值(最小为0)
    joView.handleItem = function(oItem,iIndex){
        var now = new Date().getTime();//当前时间
        var n = oItem.expireTime - now;
        if(n < 0){//已过期
            oItem.expireTime = '<span class="font-gray">' + jo.formatTime(oItem.expireTime) + '</span>';
        }else if(n < (10 * 60 * 1000) ){//10分钟内过期
            oItem.expireTime = '<span class="font-yellow">' + jo.formatTime(oItem.expireTime) + '</span>';
        }else{
            oItem.expireTime = '<span class="">' + jo.formatTime(oItem.expireTime) + '</span>';
        }
        oItem.statusMark = formatState(oItem.status);
        oItem.opt = '<button type="button" class="btn btn-warning btn-sm" onclick="offLine(\''+oItem.id+'\', \''+oItem.status+'\')"><i class="fa fa-unlink" aria-hidden="true"></i>&nbsp;下线</button>'
        oItem.opt += '&nbsp;&nbsp;<button type="button" class="btn btn-success btn-sm" onclick="onLine(\''+oItem.id+'\', \''+oItem.status+'\')"><i class="fa fa-link" aria-hidden="true"></i>&nbsp;上线</button>'
    };
    //表格渲染完成后的回调,参数为表格数据(数组对象)
    joView.setGridDataAfter = function(oList){

    };
    //格式化状态
    function formatState(state){
        if(state == 0){
            return '<span class="label label-danger">禁用</span>';
        }else if(state == 1){
            return '<span class="label label-primary">启用</span>';
        }else{
            return state;
        }
    }
    /* 关于joView更多回调函数和配置参数可查看jo-page-view.js */
    //下线
    function offLine(sessionId, status) {
        if(status == 0){
            jo.showTipsMsg('当前会话已下线!');
            return;
        }
        if(sessionId){
            jo.confirm('您确定要下线该会话?', function(){
                jo.postAjax('{URL_UMS}ums/ssoSession/offLine', {sessionId:sessionId}, function(json){
                    if(json && json.code == 0){
                        jo.showSuccessMsg('下线成功!');
                        joView.reloadCurrentPage();
                    }else{
                        jo.showErrorMsg('操作失败');
                    }
                }, true);
            });
        }
    }
    //上线
    function onLine(sessionId, status) {
        if(status == 1){
            jo.showTipsMsg('当前会话已上线!');
            return;
        }
        if(sessionId){
            jo.confirm('您确定要上线该会话?', function(){
                jo.postAjax('{URL_UMS}ums/ssoSession/onLine', {sessionId:sessionId}, function(json){
                    if(json && json.code == 0){
                        jo.showSuccessMsg('上线成功!');
                        joView.reloadCurrentPage();
                    }else{
                        jo.showErrorMsg('操作失败');
                    }
                }, true);
            });
        }
    }
</script>
</body>
</html>
